package com.woniu.springboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {


    @RequestMapping("/login")
    public String login(String username, String password, HttpServletRequest request){

        // -- 模拟 这里写死不连接数据库
        if ("admin".equals(username) && "123".equals(password)){
            // -- 成功
            request.getSession().setAttribute("userInfo",username);
            // -- 重定向到EmpController查询数据
            return "redirect:list";
        }else {
            // -- 失败
            request.setAttribute("errorInfo","用户名或者密码错误！！！");
            return "login";
        }

    }


    @RequestMapping("/logout")
    public String logout(HttpServletRequest request){
        // -- 删除session数据  这里销毁
        request.getSession().invalidate();
        return "login";
    }
}
